package com.example.bootdemo.dict.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.bootdemo.dict.service.VueDictService;
import com.example.bootdemo.dict.entity.VueDict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * 控制器
 */
@RestController
@RequestMapping("/api/dict/vue-dict")
public class VueDictController {

    @Autowired
    private VueDictService vueDictService;

    /**
     * 新增VueDict
     */
    @PostMapping("/save")
    public Boolean save(@RequestBody VueDict vueDict) {
        return vueDictService.save(vueDict);
    }

    /**
     * 删除VueDict
     */
    @DeleteMapping("/delete/{id}")
    public Boolean delete(@PathVariable Long id) {
        return vueDictService.removeById(id);
    }

    /**
     * 修改VueDict
     */
    @PostMapping("/update")
    public Boolean update(@RequestBody VueDict vueDict) {
        return vueDictService.updateById(vueDict);
    }

    /**
     * 主键查询VueDict
     */
    @GetMapping("/{id}")
    public VueDict findById(@PathVariable Long id) {
        return vueDictService.getById(id);
    }

    /**
     * 分页查询VueDict
     */
    @GetMapping("/page")
    public Page<VueDict> pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return vueDictService.page(new Page<>(pageNum, pageSize));
    }

    /**
     * 列表查询VueDict
     */
    @GetMapping("/list")
    public List<VueDict> listAll() {
        return vueDictService.list();
    }

    @GetMapping("/listByDictType")
    public List<VueDict> listByDictType(String dictType) {
        LambdaQueryWrapper<VueDict> eq = Wrappers.<VueDict>lambdaQuery().eq(VueDict::getDictType, dictType);
        return vueDictService.list(eq);
    }
}
